<?php
/* 模型 Uephp 超轻量级框架 */
namespace app\models;
class model extends \UeModel{
	
	//全局模型文件创建及命名规则
	public function census(){//缓存类
		return $this->cache('census','__census');
	}
	
	public function __census(){//数据类
		$times = time();
		$kmDB = db('kami_list');
		$data = $kmDB->fetch("count(*) as kami_num,count(case when useTime>0 then 1 end) as kami_use_num,count(case when vipExp<{$times} then 1 end) as kami_exp_num");//统计卡密数
		
		$logDB = db('logs');
		$log_list = $logDB->join("as LOG left join {$logDB->pre}kami_list as K on (LOG.uid = K.id)")->order('LOG.id desc')->limit(0,5)->fetchAll('LOG.*,K.cardNo,K.cardEmail');
		$logs = [];
		$this->logType = c('logType');
		foreach ($log_list as $rows){
			$actUser = empty($rows['uid'])?'admin':(!empty($rows['cardEmail'])?$rows['cardEmail']:$rows['cardNo']);
			$logs[] = [
				'id'=>$rows['id'],
				'actType'=>!empty($this->logType[$rows['type']])?$this->logType[$rows['type']]:$rows['type'],
				'actPerson'=>empty($rows['uid'])?'管理员':'用户',
				'actUser'=>$actUser,
				'time'=>date("Y-m-d H:i",$rows['time']),
				'ip'=>$rows['ip'],
				'state'=>$rows['code']==200?'y':'n'
			];
		}
		
		$data['logs'] = $logs;
		$data['server_info'] = [
			'sys_ver'=>c('admin.SYS_VERSION'),
			'domain'=>$_SERVER['SERVER_NAME'],
			'serverapp'=>$_SERVER["SERVER_SOFTWARE"],
			'php_ver'=>PHP_VERSION,
			'mysql_ver'=>$logDB->mysqlV(),
			'uploadfile_maxsize'=>ini_get('upload_max_filesize')
		];
		return $data;
	}
}